#!/usr/bin/env python
import sys,os
import time,datetime
def get_tck():
	return os.sysconf(os.sysconf_names['SC_CLK_TCK'])


def get_uptime():
	uptime  = open('/proc/uptime', 'r').read()
	return uptime.split()[0]

def get_start_time(pid):
	starttime_idx=21
	stat = open('/proc/%s/stat' % pid , 'r').read()
	return stat.split()[starttime_idx]


if __name__ == "__main__":

	if len(sys.argv) < 2:
		print "Usage: %s pid" % sys.argv[0]
		sys.exit(1)
	pid = sys.argv[1]
	now_seconds = time.time()
	tck = int(get_tck())
	sys_uptime = float(get_uptime())
	proc_starttime = float(get_start_time(pid))
	start_seconds = now_seconds + (proc_starttime/tck - sys_uptime)
	t = datetime.datetime.fromtimestamp(start_seconds)
	print "pid '%s', start time is: %s" % (pid, t.strftime("%F %T"))
	
